
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>序列化 · relax space</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="relax space <xiaoxm_001@outlook.com>">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-disqus/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../pypy/m1.html" />
    
    
    <link rel="prev" href="../re/m1.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    relax-space
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../../tech/">
            
                <a href="../../tech/">
            
                    
                    技术
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../../tech/mysql/m1.html">
            
                <a href="../../tech/mysql/m1.html">
            
                    
                    mysql
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../../tech/rocketmq/m1.html">
            
                <a href="../../tech/rocketmq/m1.html">
            
                    
                    rocketmq
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../../tool/">
            
                <a href="../../tool/">
            
                    
                    工具
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../../tool/git/m1.html">
            
                <a href="../../tool/git/m1.html">
            
                    
                    git
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1.1" data-path="../../tool/git/rebase/m1.html">
            
                <a href="../../tool/git/rebase/m1.html">
            
                    
                    rebase
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../../tool/idea/m1.html">
            
                <a href="../../tool/idea/m1.html">
            
                    
                    idea
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.2.1" data-path="../../tool/idea/jrebel/m1.html">
            
                <a href="../../tool/idea/jrebel/m1.html">
            
                    
                    jrebel
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2.2" data-path="../../tool/idea/git/m1.html">
            
                <a href="../../tool/idea/git/m1.html">
            
                    
                    git本地改变
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../../tool/navicat/m1.html">
            
                <a href="../../tool/navicat/m1.html">
            
                    
                    navicat
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../../tool/system/m1.html">
            
                <a href="../../tool/system/m1.html">
            
                    
                    system
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.4.1" data-path="../../tool/system/proxy/m1.html">
            
                <a href="../../tool/system/proxy/m1.html">
            
                    
                    代理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4.2" data-path="../../tool/system/ssh/m1.html">
            
                <a href="../../tool/system/ssh/m1.html">
            
                    
                    ssh
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4.3" data-path="../../tool/system/hotkey.html">
            
                <a href="../../tool/system/hotkey.html">
            
                    
                    快捷键
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../../tool/vscode/m1.html">
            
                <a href="../../tool/vscode/m1.html">
            
                    
                    vscode
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.5.1" data-path="../../tool/vscode/case/m1.html">
            
                <a href="../../tool/vscode/case/m1.html">
            
                    
                    大小写快捷键
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5.2" data-path="../../tool/vscode/proxy/m1.html">
            
                <a href="../../tool/vscode/proxy/m1.html">
            
                    
                    代理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../../tool/windows/m1.html">
            
                <a href="../../tool/windows/m1.html">
            
                    
                    windows
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.6.1" data-path="../../tool/windows/ipSwitch/m1.html">
            
                <a href="../../tool/windows/ipSwitch/m1.html">
            
                    
                    ip切换工具
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6.2" data-path="../../tool/windows/pin/m1.html">
            
                <a href="../../tool/windows/pin/m1.html">
            
                    
                    pin
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6.3" data-path="../../tool/windows/time/m1.html">
            
                <a href="../../tool/windows/time/m1.html">
            
                    
                    自动同步时间
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../../docker/">
            
                <a href="../../docker/">
            
                    
                    docker
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../../docker/it/m1.html">
            
                <a href="../../docker/it/m1.html">
            
                    
                    it命令
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../../java/">
            
                <a href="../../java/">
            
                    
                    java
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../../java/maven/m1.html">
            
                <a href="../../java/maven/m1.html">
            
                    
                    maven
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../../java/fastjson/m1.html">
            
                <a href="../../java/fastjson/m1.html">
            
                    
                    序列化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../../java/base1/m1.html">
            
                <a href="../../java/base1/m1.html">
            
                    
                    基础1
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../">
            
                <a href="../">
            
                    
                    python
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../source/m1.html">
            
                <a href="../source/m1.html">
            
                    
                    清华源
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../zone/m1.html">
            
                <a href="../zone/m1.html">
            
                    
                    时区
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../email/m1.html">
            
                <a href="../email/m1.html">
            
                    
                    邮件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../str/m1.html">
            
                <a href="../str/m1.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../param/m1.html">
            
                <a href="../param/m1.html">
            
                    
                    参数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../dict/m1.html">
            
                <a href="../dict/m1.html">
            
                    
                    字典
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../list/m1.html">
            
                <a href="../list/m1.html">
            
                    
                    列表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../set/m1.html">
            
                <a href="../set/m1.html">
            
                    
                    集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../re/m1.html">
            
                <a href="../re/m1.html">
            
                    
                    正则
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.6.10" data-path="m1.html">
            
                <a href="m1.html">
            
                    
                    序列化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.11" data-path="../pypy/m1.html">
            
                <a href="../pypy/m1.html">
            
                    
                    pypy安装
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../../golang/">
            
                <a href="../../golang/">
            
                    
                    golang
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../../golang/hello/m1.html">
            
                <a href="../../golang/hello/m1.html">
            
                    
                    hello
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../../golang/speed/m1.html">
            
                <a href="../../golang/speed/m1.html">
            
                    
                    加速
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../../golang/hello-mod/m1.html">
            
                <a href="../../golang/hello-mod/m1.html">
            
                    
                    hello-mod
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../../vip/">
            
                <a href="../../vip/">
            
                    
                    vip
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >序列化</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="json&#x5E8F;&#x5217;&#x5316;">json&#x5E8F;&#x5217;&#x5316;</h1>
<p>pytest&#x6267;&#x884C;</p>
<h2 id="&#x7B80;&#x5355;&#x5BF9;&#x8C61;">&#x7B80;&#x5355;&#x5BF9;&#x8C61;</h2>
<pre><code class="lang-python">    p = Person(<span class="hljs-string">&apos;xiao&apos;</span>)
    json1 = json.dumps(p, default=Person.to_dict)
    p2 = json.loads(json1, object_hook=Person.from_dict)
</code></pre>
<pre><code class="lang-python">
<span class="hljs-keyword">import</span> json
<span class="hljs-keyword">from</span> typing <span class="hljs-keyword">import</span> Dict


<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, name: str = <span class="hljs-string">&apos;xiaomiao&apos;</span>)</span>:</span>
        self.name = name

<span class="hljs-meta">    @staticmethod</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">to_dict</span><span class="hljs-params">(obj: object)</span>:</span>
        <span class="hljs-keyword">return</span> obj.__dict__

<span class="hljs-meta">    @classmethod</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">from_dict</span><span class="hljs-params">(cls, dict: Dict)</span>:</span>
        p = cls()
        p.__dict__ = dict
        <span class="hljs-keyword">return</span> p


<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Female</span><span class="hljs-params">(Person)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, name: str = <span class="hljs-string">&apos;xiao&apos;</span>, sex: int = <span class="hljs-number">1</span>)</span>:</span>
        self.name = name
        self.sex = sex


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_1</span><span class="hljs-params">()</span>:</span>
    p = Person(<span class="hljs-string">&apos;xiao&apos;</span>)
    json1 = json.dumps(p, default=Person.to_dict)
    <span class="hljs-keyword">assert</span> <span class="hljs-string">&apos;{&quot;name&quot;: &quot;xiao&quot;}&apos;</span> == json1, <span class="hljs-string">&apos;json dump error&apos;</span>
    p2 = json.loads(json1, object_hook=Person.from_dict)
    <span class="hljs-keyword">assert</span> p.__dict__ == p2.__dict__, <span class="hljs-string">&apos;json loads error&apos;</span>


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_2</span><span class="hljs-params">()</span>:</span>
    p_list = [Person(<span class="hljs-string">&apos;xiao1&apos;</span>), Person(<span class="hljs-string">&apos;xiao2&apos;</span>)]
    json1 = json.dumps(p_list, default=Person.to_dict)
    <span class="hljs-keyword">assert</span> <span class="hljs-string">&apos;[{&quot;name&quot;: &quot;xiao1&quot;}, {&quot;name&quot;: &quot;xiao2&quot;}]&apos;</span> == json1, <span class="hljs-string">&apos;json dump 2 error&apos;</span>
    p2_list = json.loads(json1, object_hook=Person.from_dict)
    <span class="hljs-keyword">assert</span> p_list[<span class="hljs-number">0</span>].__dict__ == p2_list[<span class="hljs-number">0</span>].__dict__ <span class="hljs-keyword">and</span> p_list[<span class="hljs-number">1</span>].__dict__ == p2_list[<span class="hljs-number">1</span>].__dict__, <span class="hljs-string">&apos;json loads 2 error&apos;</span>


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_3</span><span class="hljs-params">()</span>:</span>
    p = Female(name=<span class="hljs-string">&apos;xiao1&apos;</span>, sex=<span class="hljs-number">1</span>)
    json1 = json.dumps(p, default=Female.to_dict)
    <span class="hljs-keyword">assert</span> <span class="hljs-string">&apos;{&quot;name&quot;: &quot;xiao1&quot;, &quot;sex&quot;: 1}&apos;</span> == json1, <span class="hljs-string">&apos;json dump error&apos;</span>
    p2 = json.loads(json1, object_hook=Female.from_dict)
    <span class="hljs-keyword">assert</span> p.__dict__ == p2.__dict__, <span class="hljs-string">&apos;json loads error&apos;</span>
</code></pre>
<h2 id="&#x5D4C;&#x5957;&#x5BF9;&#x8C61;">&#x5D4C;&#x5957;&#x5BF9;&#x8C61;</h2>
<p>&#x5C40;&#x9650;&#xFF1A;&#x56E0;&#x4E3A;&#x8981;&#x4EBA;&#x4E3A;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;fullname&#x5B57;&#x6BB5;&#xFF0C;&#x6240;&#x4EE5;&#xFF0C;&#x8981; &#x5148;&#x5E8F;&#x5217;&#x5316;&#x5230;&#x6587;&#x4EF6;&#xFF0C;&#x7136;&#x540E;&#x518D;&#x53CD;&#x5E8F;&#x5217;&#x5316;</p>
<pre><code class="lang-python">    p = Person(<span class="hljs-string">&apos;xiao&apos;</span>)
    p.p1 = Person1(<span class="hljs-string">&apos;xinmiao&apos;</span>)
    json1 = json.dumps(p, default=Person.to_dict)
    p2 = json.loads(json1, object_hook=Person.from_dict)
</code></pre>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> importlib
<span class="hljs-keyword">import</span> json
<span class="hljs-keyword">from</span> typing <span class="hljs-keyword">import</span> Dict


<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person1</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, name: str = <span class="hljs-string">&apos;xiao&apos;</span>)</span>:</span>
        self.name = name


<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, name: str = <span class="hljs-string">&apos;good&apos;</span>)</span>:</span>
        self.name = name
        self.p1 = <span class="hljs-keyword">None</span>

<span class="hljs-meta">    @staticmethod</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">to_dict_pure</span><span class="hljs-params">(obj: object)</span>:</span>
        <span class="hljs-keyword">return</span> obj.__dict__

<span class="hljs-meta">    @staticmethod</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">to_dict</span><span class="hljs-params">(obj: object)</span>:</span>
        obj.__dict__.update(
            {<span class="hljs-string">&apos;fullname&apos;</span>: f<span class="hljs-string">&apos;{obj.__module__}.{obj.__class__.__name__}&apos;</span>})
        <span class="hljs-keyword">return</span> obj.__dict__

<span class="hljs-meta">    @staticmethod</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">from_dict</span><span class="hljs-params">(dict: Dict)</span>:</span>
        module, classname = dict[<span class="hljs-string">&apos;fullname&apos;</span>].rsplit(<span class="hljs-string">&apos;.&apos;</span>, <span class="hljs-number">1</span>)
        p = getattr(importlib.import_module(module), classname)()
        p.__dict__ = dict
        <span class="hljs-keyword">return</span> p


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_1</span><span class="hljs-params">()</span>:</span>
    p = Person(<span class="hljs-string">&apos;xiao&apos;</span>)
    p.p1 = Person1(<span class="hljs-string">&apos;xinmiao&apos;</span>)
    json1 = json.dumps(p, default=Person.to_dict)
    <span class="hljs-keyword">assert</span> <span class="hljs-string">&apos;{&quot;name&quot;: &quot;xiao&quot;, &quot;p1&quot;: {&quot;name&quot;: &quot;xinmiao&quot;, &quot;fullname&quot;: &quot;test_obj_conv_2.Person1&quot;}, &apos;</span> +\
        <span class="hljs-string">&apos;&quot;fullname&quot;: &quot;test_obj_conv_2.Person&quot;}&apos;</span> == json1, <span class="hljs-string">&apos;json dumps error&apos;</span>
    p2 = json.loads(json1, object_hook=Person.from_dict)
    <span class="hljs-keyword">assert</span> p.__dict__[<span class="hljs-string">&apos;name&apos;</span>] == p2.__dict__[<span class="hljs-string">&apos;name&apos;</span>] \
        <span class="hljs-keyword">and</span> p.__dict__[<span class="hljs-string">&apos;p1&apos;</span>].__dict__ == p2.__dict__[<span class="hljs-string">&apos;p1&apos;</span>].__dict__, <span class="hljs-string">&apos;json loads error&apos;</span>


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_2</span><span class="hljs-params">()</span>:</span>
    p1 = Person(<span class="hljs-string">&apos;xiao1&apos;</span>)
    p1.p1 = Person1(<span class="hljs-string">&apos;xin1&apos;</span>)
    p2 = Person(<span class="hljs-string">&apos;xiao2&apos;</span>)
    p2.p1 = Person1(<span class="hljs-string">&apos;xin2&apos;</span>)
    p_list = [p1, p2]
    json1 = json.dumps(p_list, default=Person.to_dict)
    <span class="hljs-keyword">assert</span> <span class="hljs-string">&apos;[{&quot;name&quot;: &quot;xiao1&quot;, &quot;p1&quot;: {&quot;name&quot;: &quot;xin1&quot;, &quot;fullname&quot;: &quot;test_obj_conv_2.Person1&quot;},&apos;</span> +\
        <span class="hljs-string">&apos; &quot;fullname&quot;: &quot;test_obj_conv_2.Person&quot;}, {&quot;name&quot;: &quot;xiao2&quot;, &quot;p1&quot;: {&quot;name&quot;: &quot;xin2&quot;, &apos;</span> +\
        <span class="hljs-string">&apos;&quot;fullname&quot;: &quot;test_obj_conv_2.Person1&quot;}, &quot;fullname&quot;: &quot;test_obj_conv_2.Person&quot;}]&apos;</span>, <span class="hljs-string">&apos;json dumps 2 error&apos;</span>
    p2_list = json.loads(json1, object_hook=Person.from_dict)
    <span class="hljs-keyword">assert</span> p_list[<span class="hljs-number">0</span>].__dict__[<span class="hljs-string">&apos;name&apos;</span>] == p2_list[<span class="hljs-number">0</span>].__dict__[<span class="hljs-string">&apos;name&apos;</span>] \
        <span class="hljs-keyword">and</span> p_list[<span class="hljs-number">0</span>].__dict__[<span class="hljs-string">&apos;p1&apos;</span>].__dict__ == p2_list[<span class="hljs-number">0</span>].__dict__[<span class="hljs-string">&apos;p1&apos;</span>].__dict__ \
        <span class="hljs-keyword">and</span> p_list[<span class="hljs-number">1</span>].__dict__[<span class="hljs-string">&apos;name&apos;</span>] == p2_list[<span class="hljs-number">1</span>].__dict__[<span class="hljs-string">&apos;name&apos;</span>] \
        <span class="hljs-keyword">and</span> p_list[<span class="hljs-number">1</span>].__dict__[<span class="hljs-string">&apos;p1&apos;</span>].__dict__ == p2_list[<span class="hljs-number">1</span>].__dict__[<span class="hljs-string">&apos;p1&apos;</span>].__dict__, <span class="hljs-string">&apos;json loads 2 error&apos;</span>
</code></pre>
<h2 id="pickle">pickle</h2>
<ol>
<li>&#x4F7F;&#x7528;&#x7B80;&#x5355;&#xFF0C;&#x4E0D;&#x505A;&#x8FC7;&#x591A;&#x4ECB;&#x7ECD;</li>
<li>&#x4E3B;&#x8981;&#x8BF4;&#x660E;&#x4E00;&#x4E0B; pickle&#x548C;json&#x5D4C;&#x5957;&#x5BF9;&#x8C61;&#x5E8F;&#x5217;&#x5316;&#x7684;&#x533A;&#x522B;&#xFF0C;pickle&#x5E8F;&#x5217;&#x5316;&#x5230;&#x6587;&#x4EF6;&#x4E2D;&#x662F;&#x4E8C;&#x8FDB;&#x5236;&#x683C;&#x5F0F;&#xFF0C;&#x800C;&#x4E14;&#x8FD8;&#x4F1A;&#x53D7;&#x5230;python&#x7248;&#x672C;&#x7684;&#x5F71;&#x54CD;&#xFF0C;&#x6240;&#x4EE5;&#x8FD8;&#x662F;&#x5EFA;&#x8BAE;&#x7528;json&#x5D4C;&#x5957;&#x5BF9;&#x8C61;&#x5E8F;&#x5217;&#x5316;&#x7684;&#x65B9;&#x5F0F;</li>
</ol>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../re/m1.html" class="navigation navigation-prev " aria-label="Previous page: 正则">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../pypy/m1.html" class="navigation navigation-next " aria-label="Next page: pypy安装">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"序列化","level":"1.6.10","depth":2,"next":{"title":"pypy安装","level":"1.6.11","depth":2,"path":"python/pypy/m1.md","ref":"python/pypy/m1.md","articles":[]},"previous":{"title":"正则","level":"1.6.9","depth":2,"path":"python/re/m1.md","ref":"python/re/m1.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","disqus","toggle-chapters","chapter-fold","search-pro","code","splitter","github","donate"],"ignores":["_book","node_modules"],"root":".","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"chapter-fold":{},"disqus":{"useIdentifier":false,"shortName":"relax-space"},"github":{"url":"https://github.com/relax-space"},"splitter":{},"search-pro":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"donate":{"alipay":"https://relax.elandcloud.com/resource/barcode/a1.jpg","alipayText":"支付宝打赏","button":"赏","title":"","wechat":"https://relax.elandcloud.com/resource/barcode/w1.png","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"toggle-chapters":{}},"theme":"default","author":"relax space <xiaoxm_001@outlook.com>","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"relax space","language":"zh-hans","gitbook":"3.2.3","description":"relax space"},"file":{"path":"python/serialize/m1.md","mtime":"2022-09-20T17:14:05.987Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-09-20T17:15:01.763Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/URI.js/1.16.1/URI.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-disqus/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

